<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    .box {
      width: 100px;
      height: 100px;
      background: palegreen;
      position: fixed;

      text-align: center;
      line-height: 100px;
      font-size: 15px;
    }
  </style>
</head>
<body>

</body>
</html>

<script type="module">
// 英文：
  // easing  ->  表示动画的加速度

import * as TWEEN from './tween.js';

const box = document.createElement('div')
box.style.setProperty('background-color', '#008800')
box.style.setProperty('width', '100px')
box.style.setProperty('height', '100px')
document.body.appendChild(box);

// Setup the animation loop.
function animate(time) {
	requestAnimationFrame(animate)
	TWEEN.update(time)
}
requestAnimationFrame(animate)

const coords = {x: 0, y: 0} // Start at (0, 0)
const tween = new TWEEN.Tween(coords) // Create a new tween that modifies 'coords'.
	.to({x: 500, y: 500}, 3000) // Move to (300, 200) in 1 second.
	.easing(TWEEN.Easing.Back.InOut) // Use an easing function to make the animation smooth.
	.onUpdate(() => { // 每一帧动画 执行一次 update
		// Called after tween.js updates 'coords'.
		// Move 'box' to the position described by 'coords' with a CSS translation.
		box.style.setProperty('transform', `translate(${coords.x}px, ${coords.y}px)`)
	})
	.start() // Start the tween immediately.


</script>